import { gameHelper } from "../../cccframework/Utils/GameHelpler";


const { ccclass, property } = cc._decorator;

@ccclass
export default class DotProduct extends cc.Component {

    @property(cc.Node)
    red: cc.Node = null;
    @property(cc.Node)
    white: cc.Node = null;
    @property(cc.Label)
    dotRes: cc.Label = null;

    onLoad() {
        cc.find('Canvas').on(cc.Node.EventType.TOUCH_MOVE, (touch) => {
            // let val = this.red.getPosition().cross(this.white.getPosition())
            //@ts-ignore
            // console.log('val', val)
            //@ts-ignore
            // if (val.z > 0) {

            this.red.position = this.red.parent.convertToNodeSpaceAR(gameHelper.getRealTouchWpos(touch))
            // }
        })
    }

    dot(v1: cc.Vec2, v2: cc.Vec2) {
        return v1.x * v2.x + v1.y * v2.y
    }

    update(dt) {
        let val;
        val = this.dot(this.red.position, this.white.position)
        val = this.red.position.dot(this.white.position)
        let res = Math.abs(this.red.position.mag() * this.white.position.mag());
        /**点积求夹角 */
        val = Math.acos(val / res)
        let angle = val / Math.PI * 180;
        console.log('val', val)
        this.dotRes.string = angle.toString();
    }
}
